package com.lt.test.provider.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.lt.test.api.OrderService;
import com.lt.test.entity.DTO.PageDTO;
import com.lt.test.provider.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service(version = "1.0.0")
public class OrderServiceImpl implements OrderService{

	@Autowired
	private OrderMapper orderMapper;
	
	@Override
	public void savePurchaseOrderItem(List<Map<String, String>> parameter) {
		orderMapper.savePurchaseOrderItem(parameter);
	}

	@Override
	public void updatePurchaseOrderItem(List<Map<String, String>> parameter) {
		orderMapper.updatePurchaseOrderItem(parameter);	
	}

	@Override
	public void delPurchaseOrderItem(List<Map<String, String>> parameter) {
		orderMapper.delPurchaseOrderItem(parameter);
	}

	@Override
	public void savePurchaseOrder(Map<String, String> parameter) {
		orderMapper.savePurchaseOrder(parameter);	
	}

	@Override
	public void updatePurchaseOrder(Map<String, String> parameter) {
		orderMapper.updatePurchaseOrder(parameter);
		
	}

	@Override
	public PageDTO<Map<String, Object>> getDprodViewList(Map<String,String> stringMap) {
		
		int pageSize = Integer.valueOf(stringMap.get("pageSize"));

		int page = stringMap.get("page") == null ? 1 : Integer.valueOf(stringMap.get("page"));

		Integer beginNum = ((page - 1) * pageSize + 1);
		Integer endNum = beginNum + pageSize - 1;

        stringMap.put("beginNum",beginNum.toString());
        stringMap.put("endNum",endNum.toString());
        PageDTO<Map<String,Object>> result = null;
        try{
        	List<Map<String, Object>> infoList = orderMapper.getDprodViewList(stringMap);
        	int recordCount = orderMapper.getDprodViewCount(stringMap);
        	result = new PageDTO<>(page, pageSize, infoList, recordCount);
        } catch (Exception e) {
            e.printStackTrace();
        //    throw new CustomException("获取商品列表失败");
        }
		return result;
	}

	@Override
	public List<Map<String, Object>> getShopInStockItem(Map<String,String> parameter) {
		// TODO Auto-generated method stub
		return orderMapper.getShopInStockItem(parameter);
	}

}
